{include file="index/_meta" /}
    <title>地址管理</title>
</head>
<body>
<div id="app">
    <van-nav-bar
            title="地址管理"
            left-text="返回"
            left-arrow
            @click-left="window.history.back();"
    ></van-nav-bar>

    <van-address-edit
            :area-list="areaList"
            :address-info="addressInfo"
            show-postal
            show-delete
            show-set-default
            show-search-result
            detail-rows="3"
            :area-columns-placeholder="['请选择', '请选择', '请选择']"
            @save="onSave"
            @delete="onDelete"
    ></van-address-edit>
</div>
<script>
    new Vue({
        el: "#app",
        data(){return{
            id: '{$id}',
            show_delete: false,
            areaList: {},
            addressInfo: {},
            yes:true,
        }},
        created(){
            this.getAreaList()
        },
        methods:{
            getAreaList(){
              let that = this
              axios.post("{:url('user/getAreaList')}").then(function (ret) {
                  that.areaList = ret.data.data
                  if (that.id != ''){
                      that.getAddressInfo()
                  }
              })
            },
            onSave(content) {
                content.id = this.id
                let that = this
                axios.post("{:url('user/saveHarvestAddress')}",content).then(function (ret) {
                    if (ret.data.code == 0){
                        vant.Notify({ type: 'success', message: ret.data.msg,duration: 1000,onClose:function () {
                                window.history.back()
                            }});
                    }else{
                        vant.Notify({ type: 'danger', message: ret.data.msg,duration: 1000,});
                    }
                })
            },
            onDelete() {
                let that = this
                axios.post("{:url('user/userAddressDel')}",{id:that.id}).then(function (ret) {
                    vant.Notify({ type: 'success', message: ret.data.msg,duration: 1000,onClose:function () {
                            window.history.back();
                        }});
                })
            },
            getAddressInfo(){
                let that = this
                axios.post("{:url('user/getAddressInfo')}",{id:that.id}).then(function (ret) {
                    that.addressInfo = ret.data.data
                })
            },
        },
    })
</script>
</body>
</html>
